import 'package:flutter/material.dart';
import 'package:flutter_learn_vi/src/bean/bean_user_account.dart';
import 'package:get/get.dart';
import 'package:get/get_state_manager/src/simple/get_state.dart';

import '../controller/special_account_details_controller.dart';

class SpecialAccountDetailsWidget extends StatefulWidget {
  final String tag;

  const SpecialAccountDetailsWidget({Key key, this.tag}) : super(key: key);

  @override
  State<StatefulWidget> createState() {
    return _AccountDetailsState();
  }
}

class _AccountDetailsState extends State<SpecialAccountDetailsWidget> {
  SpecialAccountDetailsController _specialAccountDetailsController;

  @override
  void initState() {
    super.initState();
    _specialAccountDetailsController =
        Get.put(SpecialAccountDetailsController(), tag: widget.tag);
    Future.delayed(Duration.zero, () {
      _specialAccountDetailsController.requestUserAccount();
    });
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      child: Hero(
        tag: "accountCenter",
        child: Material(
          child: Container(
            margin: EdgeInsets.only(bottom: 8, left: 12, right: 12),
            padding: EdgeInsets.all(10),
            decoration: BoxDecoration(
                gradient: LinearGradient(
                    colors: [Color(0xfff87272), Color(0xF0F4833E)]),
                borderRadius: BorderRadius.all(Radius.circular(4))),
            child: Container(
              child: GetBuilder(
                tag: widget.tag,
                id: "userSpecialAccount",
                builder: (SpecialAccountDetailsController controller) {
                  UserSpecialAccountBean bean = controller.userAccountStateBean;
                  num total = 0;
                  num yestoday = 0;
                  num weekDataNum = 0;
                  num monthDataNum = 0;
                  return GestureDetector(
                    onTap: () {},
                    child: Row(
                      children: [
                        buildItem(title: "严重三违", score: bean.sanweiAmount),
                        buildItem(title: "潜力员工", score: bean.qianliAmount),
                        buildItem(title: "不胜任岗位", score: bean.noWorkAmount),
                      ],
                    ),
                  );
                },
              ),
            ),
          ),
        ),
      ),
    );
  }

  buildItem({String title, num score}) {
    return Expanded(
      child: Column(
        mainAxisSize: MainAxisSize.min,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          Text(
            "$title",
            style: TextStyle(fontSize: 16, color: Color(0xffffffff)),
          ),
          SizedBox(
            height: 16,
          ),
          Text(
            "$score",
            textAlign: TextAlign.center,
            style: TextStyle(fontSize: 14, color: Color(0xffffffff)),
          ),
        ],
      ),
    );
  }
}
